/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Stampa.java
 *
 * Created on 3-dic-2010, 13.03.01
 */
package gastoneView;

import Entity.Scommessa;
import Entity.Sistema;
import Entity.TipoScommessa;
import Entity.SistemaComparatorFissa;
import Entity.SistemaComparatorVittoriaMassima;
import Entity.SistemaComparatorVittoriaMinima;
import java.awt.Cursor;
import java.awt.Toolkit;
import java.util.Collections;
import java.util.Vector;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.filechooser.FileNameExtensionFilter;

import betSystems.GastoneSimulator;

/**
 *
 * @author francesco
 */
public class Stampa extends javax.swing.JFrame {

    private GastoneSimulator snaisimulator;
    Vector<JComponent> pannelloOpzioni = new Vector<JComponent>();
    Vector<Sistema> daStampare;

    public Stampa(GastoneSimulator s) {
        snaisimulator = s;
        daStampare = s.getSistemi();

        initComponents();
        
        lblContententiLeSeguenti.setText("\ne contententi le seguenti partite (max 4)");

        org.jdesktop.application.ResourceMap resourceMap =
                org.jdesktop.application.Application.getInstance(
                gastoneView.GastoneApp.class).getContext().getResourceMap(GastoneAboutBox.class);

        Icon icon = resourceMap.getIcon("imageLabel.icon");

        jOptionPane1.setIcon(icon);
        this.setIconImage(((ImageIcon) icon).getImage());

        this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

        lblNumeroSistemiGenerati.setText("Generati " + snaisimulator.getContatoresistemi() + " sistemi.");

        this.setLocationRelativeTo(null);

        cmbFissa.removeAllItems();

        Vector<Scommessa> partiteEdEventi = new Vector<Scommessa>();

        for (Sistema sis : snaisimulator.getSistemi()) {
            if (!partiteEdEventi.contains(sis.getFissa())) {
                partiteEdEventi.add(sis.getFissa());
            }
        }

        Collections.sort(partiteEdEventi);

        partiteEdEventi.add(0, new Scommessa(-1, 0, "Qualunque fissa", null));

        for (Scommessa sc : partiteEdEventi) {
            cmbFissa.addItem(sc);
        }

        partiteEdEventi.removeAllElements();

        for (Sistema sis : snaisimulator.getSistemi()) {
            for (Scommessa sc : sis.getPartite()) {
                if (!partiteEdEventi.contains(sc)) {
                    partiteEdEventi.add(sc);
                }
            }
        }

        Collections.sort(partiteEdEventi);

        jListPartite.setListData(partiteEdEventi);

        pannelloOpzioni.add(radioFissa);
        pannelloOpzioni.add(radioNumero);
        pannelloOpzioni.add(lblContententiLeSeguenti);
        pannelloOpzioni.add(cmbFissa);
        pannelloOpzioni.add(cmbProbVitt);
        pannelloOpzioni.add(cmbNumero);
        pannelloOpzioni.add(lblSistemi);
        pannelloOpzioni.add(lblSelezioneMultipla);
        for (JComponent j : pannelloOpzioni) {
            j.setEnabled(false);
        }

        jPanel4.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(192, 192, 192), 1, true));

        cmbNumero.removeAllItems();

        for (int i = 1; i < s.getContatoresistemi(); i++) {
            cmbNumero.addItem(i);
        }

        jFileChooser1.setMultiSelectionEnabled(false);
        jFileChooser1.setFileFilter(new FileNameExtensionFilter("Portable docoment format", "pdf"));



    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jOptionPane1 = new javax.swing.JOptionPane();
        jFileChooser1 = new javax.swing.JFileChooser();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        lblNumeroSistemiGenerati = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        radioFissa = new javax.swing.JRadioButton();
        radioNumero = new javax.swing.JRadioButton();
        cmbNumero = new javax.swing.JComboBox();
        lblSistemi = new javax.swing.JLabel();
        cmbProbVitt = new javax.swing.JComboBox();
        cmbFissa = new javax.swing.JComboBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListPartite = new javax.swing.JList();
        lblSelezioneMultipla = new javax.swing.JLabel();
        lblContententiLeSeguenti = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jCheckBox1 = new javax.swing.JCheckBox();
        btnStampaSistemi = new javax.swing.JButton();
        cmbOrdinamento = new javax.swing.JComboBox();

        jOptionPane1.setName("jOptionPane1"); // NOI18N

        jFileChooser1.setName("jFileChooser1"); // NOI18N

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance().getContext().getResourceMap(Stampa.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        setResizable(false);

        jPanel1.setName("jPanel1"); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        lblNumeroSistemiGenerati.setText(resourceMap.getString("lblNumeroSistemiGenerati.text")); // NOI18N
        lblNumeroSistemiGenerati.setName("lblNumeroSistemiGenerati"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblNumeroSistemiGenerati)
                .addContainerGap(562, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblNumeroSistemiGenerati)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        jPanel4.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
        jPanel4.setName("jPanel4"); // NOI18N

        buttonGroup1.add(radioFissa);
        radioFissa.setText(resourceMap.getString("radioFissa.text")); // NOI18N
        radioFissa.setName("radioFissa"); // NOI18N
        radioFissa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioFissaActionPerformed(evt);
            }
        });

        buttonGroup1.add(radioNumero);
        radioNumero.setText(resourceMap.getString("radioNumero.text")); // NOI18N
        radioNumero.setName("radioNumero"); // NOI18N
        radioNumero.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioNumeroActionPerformed(evt);
            }
        });

        cmbNumero.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbNumero.setName("cmbNumero"); // NOI18N

        lblSistemi.setText(resourceMap.getString("lblSistemi.text")); // NOI18N
        lblSistemi.setName("lblSistemi"); // NOI18N

        cmbProbVitt.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "con probabilità più alta.", "con vittoria massima più alta.", "con vittoria minima più alta." }));
        cmbProbVitt.setName("cmbProbVitt"); // NOI18N
        cmbProbVitt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbProbVittActionPerformed(evt);
            }
        });

        cmbFissa.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbFissa.setName("cmbFissa"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jListPartite.setEnabled(false);
        jListPartite.setName("jListPartite"); // NOI18N
        jScrollPane1.setViewportView(jListPartite);

        lblSelezioneMultipla.setText(resourceMap.getString("lblSelezioneMultipla.text")); // NOI18N
        lblSelezioneMultipla.setName("lblSelezioneMultipla"); // NOI18N

        lblContententiLeSeguenti.setText(resourceMap.getString("lblContententiLeSeguenti.text")); // NOI18N
        lblContententiLeSeguenti.setName("lblContententiLeSeguenti"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(radioNumero)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cmbNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblSistemi))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(lblSelezioneMultipla))
                    .addComponent(radioFissa)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(lblContententiLeSeguenti)))
                .addGap(38, 38, 38)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmbProbVitt, 0, 299, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 299, Short.MAX_VALUE)
                    .addComponent(cmbFissa, 0, 299, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(cmbFissa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(8, 8, 8))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(radioFissa)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)))
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(lblContententiLeSeguenti)
                        .addGap(10, 10, 10)
                        .addComponent(lblSelezioneMultipla))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 237, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radioNumero)
                    .addComponent(cmbNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblSistemi)
                    .addComponent(cmbProbVitt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(12, 12, 12))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel3.setName("jPanel3"); // NOI18N

        jCheckBox1.setSelected(true);
        jCheckBox1.setText(resourceMap.getString("jCheckBox1.text")); // NOI18N
        jCheckBox1.setName("jCheckBox1"); // NOI18N
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        btnStampaSistemi.setText(resourceMap.getString("btnStampaSistemi.text")); // NOI18N
        btnStampaSistemi.setName("btnStampaSistemi"); // NOI18N
        btnStampaSistemi.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStampaSistemiActionPerformed(evt);
            }
        });

        cmbOrdinamento.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Ordina per probabilità", "Ordina per vittoria massima", "Ordina per vittoria minima", "Ordina per partita fissa" }));
        cmbOrdinamento.setName("cmbOrdinamento"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jCheckBox1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 164, Short.MAX_VALUE)
                .addComponent(cmbOrdinamento, javax.swing.GroupLayout.PREFERRED_SIZE, 204, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnStampaSistemi)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jCheckBox1)
                        .addComponent(cmbOrdinamento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnStampaSistemi, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        if (jCheckBox1.isSelected()) {
            for (JComponent j : pannelloOpzioni) {
                j.setEnabled(false);
            }
            jPanel4.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(192, 192, 192), 1, true));
            cmbOrdinamento.setEnabled(true);
            this.daStampare = snaisimulator.getSistemi();

        } else {
            for (JComponent j : pannelloOpzioni) {
                j.setEnabled(true);
            }
            jPanel4.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 1, true));
            radioFissaActionPerformed(evt);
            radioFissa.setSelected(true);
        }
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void radioFissaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioFissaActionPerformed
        cmbNumero.setEnabled(false);
        jListPartite.setEnabled(true);
        cmbProbVitt.setEnabled(false);
        cmbFissa.setEnabled(true);
        cmbOrdinamento.setEnabled(true);
    }//GEN-LAST:event_radioFissaActionPerformed

    private void radioNumeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioNumeroActionPerformed
        cmbNumero.setEnabled(true);
        jListPartite.setEnabled(false);
        cmbProbVitt.setEnabled(true);
        cmbFissa.setEnabled(false);
        cmbProbVittActionPerformed(evt);
    }//GEN-LAST:event_radioNumeroActionPerformed

    private void btnStampaSistemiActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStampaSistemiActionPerformed

        boolean giaOrdinati = false;

        if (!jCheckBox1.isSelected()) {

            if (radioFissa.isSelected()) {

                if (cmbFissa.getSelectedIndex() == 0) {
                    // Qualunque fissa
                    Vector<Scommessa> tmp = new Vector<Scommessa>();
                    for (Object obj : jListPartite.getSelectedValues()) {
                        tmp.add((Scommessa) (obj));
                    }
                    if (tmp.size() > 4) {
                        jOptionPane1.showMessageDialog(this, "Selezionare un numero di partite minore o uguale a quattro.");
                        daStampare.clear();
                    } else {
                        if (tmp.size() != 0) {
                            daStampare = snaisimulator.cercaPartite(snaisimulator.getSistemi(), tmp);
                        } else {
                            daStampare = snaisimulator.getSistemi();
                        }
                    }
                } else {

                    daStampare = snaisimulator.cercaFissa((Scommessa) cmbFissa.getSelectedItem());

                    Vector<Scommessa> tmp = new Vector<Scommessa>();
                    for (Object obj : jListPartite.getSelectedValues()) {
                        tmp.add((Scommessa) (obj));
                    }
                    if (tmp.size() > 4) {
                        jOptionPane1.showMessageDialog(this, "Selezionare un numero di partite minore o uguale a quattro.");
                        daStampare.clear();
                    } else {
                        if (tmp.size() != 0) {
                            daStampare = snaisimulator.cercaPartite(daStampare, tmp);
                        } 
                    }

                }

            } else {

                if (radioNumero.isSelected()) {

                    daStampare = snaisimulator.getSistemi();

                    if (cmbProbVitt.getSelectedItem().toString().equals("con probabilità più alta.")) {
                        Collections.sort(daStampare);
                    }

                    if (cmbProbVitt.getSelectedItem().toString().equals("con vittoria massima più alta.")) {
                        Collections.sort(daStampare, new SistemaComparatorVittoriaMassima());
                    }

                    if (cmbProbVitt.getSelectedItem().toString().equals("con vittoria minima più alta.")) {
                        Collections.sort(daStampare, new SistemaComparatorVittoriaMinima());
                    }

                    Vector<Sistema> tmp = new Vector<Sistema>();

                    for (int i = 0; i <= cmbNumero.getSelectedIndex(); i++) {
                        tmp.add(daStampare.get(i));
                    }

                    daStampare = tmp;

                    giaOrdinati = true;

                }

            }
        } else {
            daStampare = snaisimulator.getSistemi();
        }


        if (!giaOrdinati) {
            // Ordinamento
            if (cmbOrdinamento.getSelectedItem().toString() == "Ordina per vittoria massima") {
                Collections.sort(daStampare, new SistemaComparatorVittoriaMassima());
            }

            if (cmbOrdinamento.getSelectedItem().toString() == "Ordina per vittoria minima") {
                Collections.sort(daStampare, new SistemaComparatorVittoriaMinima());
            }

            if (cmbOrdinamento.getSelectedItem().toString() == "Ordina per probabilità") {
                Collections.sort(daStampare);
            }

            if (cmbOrdinamento.getSelectedItem().toString() == "Ordina per partita fissa") {
                Collections.sort(daStampare, new SistemaComparatorFissa());
            }
        }


        if (daStampare.size() == 0) {
            jOptionPane1.showMessageDialog(this, "Nessun sistema da stampare.");
            return;
        }

        int risposta = jOptionPane1.showConfirmDialog(this, "Confermi la stampa di " + daStampare.size() + " sistemi?");

        if (risposta == jOptionPane1.YES_OPTION) {

            risposta = jFileChooser1.showSaveDialog(this);

            if (risposta == jFileChooser1.APPROVE_OPTION) {

                this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                snaisimulator.printSistemi(daStampare, jFileChooser1.getSelectedFile());
                this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                jOptionPane1.showMessageDialog(this, "Stampa completata.");

            }

        }



    }//GEN-LAST:event_btnStampaSistemiActionPerformed

    private void cmbProbVittActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbProbVittActionPerformed

        //Ordina per probabilità
        //Ordina per vittoria massima
        //Ordina per vittoria minima
        //Ordina per partita fissa

        if (cmbProbVitt.getSelectedItem().toString().equals("con probabilità più alta.")) {
            cmbOrdinamento.setSelectedIndex(0);
        }

        if (cmbProbVitt.getSelectedItem().toString().equals("con vittoria massima più alta.")) {
            cmbOrdinamento.setSelectedIndex(1);
        }

        if (cmbProbVitt.getSelectedItem().toString().equals("con vittoria minima più alta.")) {
            cmbOrdinamento.setSelectedIndex(2);
        }

        cmbOrdinamento.setEnabled(false);
    }//GEN-LAST:event_cmbProbVittActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnStampaSistemi;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JComboBox cmbFissa;
    private javax.swing.JComboBox cmbNumero;
    private javax.swing.JComboBox cmbOrdinamento;
    private javax.swing.JComboBox cmbProbVitt;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JList jListPartite;
    private javax.swing.JOptionPane jOptionPane1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblContententiLeSeguenti;
    private javax.swing.JLabel lblNumeroSistemiGenerati;
    private javax.swing.JLabel lblSelezioneMultipla;
    private javax.swing.JLabel lblSistemi;
    private javax.swing.JRadioButton radioFissa;
    private javax.swing.JRadioButton radioNumero;
    // End of variables declaration//GEN-END:variables
}
